// // Copyright (c) 2009 All Right Reserved // // vl // // 2009-01-01 // Contains ... using System.Diagnostics.Contracts; using System.Globalization; using System.Text; using System.Xml.Linq; using JetBrains.Annotations; using LargoCommon.Localization; using LargoCommon.Support; namespace LargoCommon.Music { /// Musical material. /// Musical class. //// [Serializable] [ContractVerification(false)] public sealed class OrchestraTrack { //// partial #region Constructors /// /// Initializes a new instance of the OrchestraTrack class. /// /// The given octave. /// The given instrument. public OrchestraTrack(MusicalOctave givenOctave, MusicalInstrument givenInstrument) //// int scoreLineId : this() { this.Octave = givenOctave; this.BandType = MusicalProperties.BandTypeFromOctave(givenOctave); this.Instrument = givenInstrument; } /// Initializes a new instance of the class. /// The given instrument. public OrchestraTrack(MusicalInstrument givenInstrument) //// int scoreLineId : this() { this.Octave = MusicalOctave.None; this.BandType = MusicalBand.MiddleBeat; this.Instrument = givenInstrument; } /// /// Initializes a new instance of the class. /// public OrchestraTrack() { this.Instrument = new MusicalInstrument(MidiMelodicInstrument.AcousticGrandPiano); } /// /// Initializes a new instance of the class. /// /// The given line. public OrchestraTrack(XElement xtrack) { Contract.Requires(xtrack != null); if (xtrack == null) { return; } this.Octave = DataEnums.ReadAttributeMusicalOctave(xtrack.Attribute("Octave")); this.BandType = DataEnums.ReadAttributeMusicalBandType(xtrack.Attribute("Band")); var xInstrument = xtrack.Element("Instrument"); this.Instrument = new MusicalInstrument(xInstrument); if (this.Instrument.Genus == InstrumentGenus.Melodical) { var melodicGroup = InstrumentsPorter.GetGroupOfMelodicInstrument(this.Instrument.Number); this.InstrumentGroupString = melodicGroup.ToString(); } else { var rhythmicGroup = InstrumentsPorter.GetGroupOfRhythmicInstrument(this.Instrument.Number); this.InstrumentGroupString = rhythmicGroup.ToString(); } } #endregion #region Properties - Xml /// /// Gets the get x element. /// /// /// The get x element. /// public XElement GetXElement { get { XElement xtrack = new XElement( "Track", new XAttribute("Band", this.BandType), new XAttribute("Octave", this.Octave)); xtrack.Add(this.Instrument.GetXElement); return xtrack; } } #endregion #region Properties /// /// Gets or sets the instrument. /// /// /// The instrument. /// [UsedImplicitly] public MusicalInstrument Instrument { get; set; } /// Gets or sets the instrument group string. /// The instrument group string. public string InstrumentGroupString { get; set; } /// /// Gets the instrument number. /// /// /// The instrument number. /// public byte InstrumentNumber => this.Instrument?.Number ?? (byte)MidiMelodicInstrument.AcousticGrandPiano; /// /// Gets or sets the type of the band. /// /// /// The type of the band. /// public MusicalBand BandType { get; set; } /// /// Gets or sets the octave. /// /// /// The octave. /// public MusicalOctave Octave { get; set; } /// /// Gets or sets a value indicating whether this instance is used. /// /// /// true if this instance is used; otherwise, false. /// public bool IsUsed { get; set; } /// /// Gets Unique Identifier. /// /// Property description. public string UniqueIdentifier => $"{this.BandType}{this.Instrument}"; #endregion #region Export /// /// Gets OctaveString. /// /// General musical property. [UsedImplicitly] public string OctaveString => LocalizedMusic.String("Octave" + ((int)this.Octave).ToString(CultureInfo.CurrentCulture)); /// /// Gets BandTypeString. /// /// Property description. [UsedImplicitly] public string BandTypeString => LocalizedMusic.String("Band" + ((int)this.BandType).ToString(CultureInfo.CurrentCulture)); /// /// Gets the instrument string. /// /// /// The instrument string. /// public string InstrumentString => this.Instrument.ToString(); #endregion #region String representation /// String representation of the object. /// Returns value. public override string ToString() { var s = new StringBuilder(); s.Append(this.OctaveString + "-"); s.Append(this.BandTypeString + ": "); s.AppendLine(this.Instrument.ToString()); //// s.Append("\t" + this.RhythmicOrder.ToString(CultureInfo.CurrentCulture)); return s.ToString(); } #endregion } }